package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo07 {
    public static void main(String[] args) {
        try (Connection conn = DBUtils.getConn();)
        {
            String sql = "select * from user limit ?,?";
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入要查询的页数:");
            int page = scanner.nextInt();
            System.out.print("请输入要查询的条数:");
            int number = scanner.nextInt();
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1,(page-1)*number);
            ps.setInt(2,number);
            ResultSet rs = ps.executeQuery();
            while (rs.next()){
                int id = rs.getInt("id");
                String username = rs.getString("username");
                String password = rs.getString("password");
                System.out.println("id:"+id+"\tusername:"+username+"\tpassword:"+password);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
